package com.module.product.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import base.dao.GenericHibernateDao;

import com.module.product.vo.SynStatus;

/**
 * 
 * 数据同步记录表
 * 
 * @author zhangjy
 */
public class SynStatusDao  extends GenericHibernateDao<SynStatus, Long >{
	private static final SynStatusDao instance = new SynStatusDao();

	private SynStatusDao() {
	}

	public synchronized static SynStatusDao getInstance() {
		return instance;
	}

	/**
	 * 根据企业ID和表名获取已同步的ID
	 * @param session
	 * @param orgid
	 * @return
	 */
	public Long getIdByorgIdAndTableName(Session session, String orgid ,String tableName) {
		StringBuffer hql = new StringBuffer();
		hql.append("select o.iSyscId from SynStatus o where o.tableName = '"+tableName+"' and o.orgId ='"
				+ orgid + "' order by syscTime desc");
		Query query = session.createQuery(hql.toString());
		
		Long  syscId = 0L;
		
		List list = query.list();
		
		if(list != null && list.size() >0){
			syscId = (Long)list.get(0);
		}

		
		return syscId;
	}
	


}
